package jtg.generator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class JUnitGenerator extends Generator {

    public JUnitGenerator(String className, String methodName) {
        super(className, methodName);
        String defaultClsPath = System.getProperty("user.dir") + File.separator + "target" + File.separator + "classes";
        new JUnitGenerator(defaultClsPath, className, methodName);
    }

    public JUnitGenerator(String classPath, String className, String methodName) {
        super(classPath, className, methodName);
    }

    @Override
    void drawCFG() {

    }

    @Override
    List<String> generate() {
        return null;
    }

    public String generateJUnitTests(List<String> testCases) {
        StringBuilder junitCode = new StringBuilder();
        junitCode.append("@ParameterizedTest\n");
        junitCode.append("@CsvSource({\n");
        for (String testCase : testCases) {
            junitCode.append("    \"" + testCase + "\",\n");
        }
        junitCode.deleteCharAt(junitCode.length() - 2);
        junitCode.append("})\n");
        junitCode.append("void " + mtdName + "Test(int a, int b, int c) {\n");
        junitCode.append("    assertEquals(" + mtdName + "(a, b), c);\n");
        junitCode.append("}\n");
        return junitCode.toString();
    }

    public static void main(String[] args) {
//        StateCoverageGenerator scg = new StateCoverageGenerator(System.getProperty("user.dir") + "/target/test-classes","cut.LogicStructure","ifElse");
//        List<String> testCases = scg.generate();
        List<String> testCases = new ArrayList<>();
        testCases.add("1,2,3");
        testCases.add("-1,-2,-3");
        JUnitGenerator jg = new JUnitGenerator(System.getProperty("user.dir") + "/target/test-classes","cut.LogicStructure","ifElse");
        String junitCode = jg.generateJUnitTests(testCases);
        System.out.println(junitCode);
    }
}

